//
//  AditCustomerApi.m
//  EMMApp
//
//  Created by Mac on 16/5/25.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "EditCustomerApi.h"
#define myUrlMethod @"editCustomer"
#define myUrlPath @"/appapi/editCustomer"

@implementation EditCustomerApi
{
    NSString *_body;
}

- (instancetype)initWithCustomerId:(NSString *)customerId
                      customerName:(NSString *)customerName
                      customerStar:(NSString *)customerStar
                       customerSex:(NSString *)customerSex
                     customerPhone:(NSString *)customerPhone
                    intentionLevel:(NSString *)intentionLevel
                    customerOrigin:(NSString *)customerOrigin
                    customerStatus:(NSString *)customerStatus
                    rqTheirMotives:(NSString *)rqTheirMotives
                         rqFocusId:(NSString *)rqFocusId
                      rqDemandArea:(NSString *)rqDemandArea
                   rqPaymentMethod:(NSString *)rqPaymentMethod
                      rqServicesId:(NSString *)rqServicesId
                          roomList:(NSArray *)roomList
                      ftContactWay:(NSString *)ftContactWay
                     ftContactTime:(NSString *)ftContactTime
                  ftContactContent:(NSString *)ftContactContent
             peResidenceProvinceId:(NSString *)peResidenceProvinceId
                 peResidenceCityId:(NSString *)peResidenceCityId
                 peResidenceAreaId:(NSString *)peResidenceAreaId
            peWorkaroundProvinceId:(NSString *)peWorkaroundProvinceId
                peWorkaroundCityId:(NSString *)peWorkaroundCityId
                peWorkaroundAreaId:(NSString *)peWorkaroundAreaId
                          industry:(NSString *)industry
              intentionLevelRemark:(NSString *)intentionLevelRemark
                       informedWay:(NSString *)informedWay
               recommendedCategory:(NSString *)recommendedCategory
                   recommendedName:(NSString *)recommendedName
                 recommendedMobile:(NSString *)recommendedMobile
                   recommendedUnit:(NSString *)recommendedUnit newNote:(NSString *)note{
    
    self = [super init];
    if (self) {
        NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
        NSString *merchantId = [userdf objectForKey:@"merchantId"];
        NSString *userId = [userdf objectForKey:@"userNameId"];
        NSString *token = [userdf objectForKey:@"is_login"];
        NSString *projectCode = [userdf objectForKey:@"projectCode"];
//        NSString *projectId = [userdf objectForKey:@"projectId"];

        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        [params setValue:apiVersion forKey:@"version"];
        [params setValue:[IDTools devId2] forKey:@"terminalCode"];
        [params setValue:merchantId forKey:@"merchantId"];
        [params setValue:userId forKey:@"userId"];
        [params setValue:token forKey:@"token"];
        [params setValue:projectCode forKey:@"projectCode"];
//        [params setValue:projectId forKey:@"projectId"];

        [params setValue:customerId forKey:@"customerId"];
        [params setValue:customerName forKey:@"customerName"];
        [params setValue:customerStar forKey:@"customerStar"];
        [params setValue:customerSex forKey:@"customerSex"];
        [params setValue:customerPhone forKey:@"customerPhone"];
        [params setValue:intentionLevel forKey:@"intentionLevel"];
        [params setValue:customerOrigin forKey:@"customerOrigin"];
        [params setValue:customerStatus forKey:@"customerStatus"];
        
        [params setValue:informedWay forKey:@"informedWay"];
        [params setValue:recommendedCategory forKey:@"recommendedCategory"];
        [params setValue:recommendedName forKey:@"recommendedName"];
        [params setValue:recommendedMobile forKey:@"recommendedMobile"];
        [params setValue:recommendedUnit forKey:@"recommendedUnit"];
        
        //需求
        [params setValue:rqTheirMotives forKey:@"rqTheirMotives"];
        [params setValue:rqDemandArea forKey:@"rqDemandArea"];
        [params setValue:rqFocusId forKey:@"rqFocusId"];
        [params setValue:rqPaymentMethod forKey:@"rqPaymentMethod"];
        [params setValue:rqServicesId forKey:@"rqServicesId"];
        [params setValue:roomList forKey:@"roomList"];
        
        //初次
        [params setValue:ftContactWay forKey:@"ftContactWay"];
        [params setValue:ftContactTime forKey:@"ftContactTime"];
        [params setValue:ftContactContent forKey:@"ftContactContent"];
        [params setValue:note forKey:@"ftContactContent1"];
        
        //客户个人信息
        [params setValue:peResidenceProvinceId forKey:@"peResidenceProvinceId"];
        [params setValue:peResidenceCityId forKey:@"peResidenceCityId"];
        [params setValue:peResidenceAreaId forKey:@"peResidenceAreaId"];
        
        [params setValue:peWorkaroundProvinceId forKey:@"peWorkaroundProvinceId"];
        [params setValue:peWorkaroundCityId forKey:@"peWorkaroundCityId"];
        [params setValue:peWorkaroundAreaId forKey:@"peWorkaroundAreaId"];

        [params setValue:industry forKey:@"industry"];
        [params setValue:intentionLevelRemark forKey:@"intentionLevelRemark"];

        _body = [@{@"params" : params} JSONString];
        NSLog(@"%@:\n %@%@?body=%@", myUrlMethod, apiBaseUrl, myUrlPath, _body);
    }
    return self;
}

#pragma mark - 父类继承拓展

- (NSString *)requestUrl
{
    return myUrlPath;
}

- (id)requestArgument
{
    return @{ @"body" : _body };
}

- (NSString *)methodString
{
    return myUrlMethod;
}


#pragma mark - 通用

- (EditCustomer *)resultData
{
    id myObj = [IDTools jsonStrToObjc:self.responseString method:myUrlMethod];
    
    EditCustomer *data = (EditCustomer *)myObj;
    
    NSLog(@"%@ resultData is %@", myUrlMethod, data);
    
    return data;
}

- (BOOL)isSuccess
{
    NSString *str = [[self resultData] result];
    if ([NSString isStringEmpty:str] || ![str isEqualToString:@"1"]) {
        return NO;
    } else {
        return YES;
    }
}

@end
